<?php
/******************************************
 * Author: <YOUR NAME HERE>
 * Description: <YOUR DESCRIPTION HERE>
 ******************************************/
class Players  extends CustomSecurity { 

	var $db; 
	var $id;
	var $possition;
	var $name;
	var $cc;

	function Players($db){ 
          $this->db = $db; 
    }

//	/***********************************
// 	 * Add:         Allows the insertion of values into the Table.
// 	 * Parameters:  $id, $possition, $name, $cc
// 	 * Return:      (Boolean) True - Successfully Inserted | False - Error
// 	 ************************************/
//	function add($id, $possition, $name, $cc){ 
//
//		//Custom SQL Injection Escaping HERE
//
//		$statement = "INSERT INTO players (id, possition, name, cc) VALUES ('$id', '$possition', '$name', '$cc');";
//		$results   = $this->db->query($statement);
//
//		if($results){
//			return true;
//		}else{
//			return false;
//		}
//
//	}//End add()


//	/***********************************
// 	 * Remove:      Allows for the removal of record from the database.
// 	 * Parameters:  (String)Primary Key Column Name | (Int) Primary Key Value
// 	 * Return:      (Boolean) True - Successfully Removed | False - Error
// 	 ************************************/
//	function remove($primaryKeyName, $primaryKeyValue){ 
//
//		//Custom SQL Injection Escaping HERE
//
//		$statement = "DELETE FROM players WHERE $primaryKeyName = '$primaryKeyValue'";
//		$results   = $this->db->query($statement);
//		if($results){
//			return true;
//		}else{
//			return false;
//		}
//
//	}//End remove()
//

//	/***********************************
// 	 * Update:      Allows for the update of a record from the database.
// 	 * Parameters:  (String)Primary Key Column Name | (Int) Primary Key Value | (String) Column Name To Update | (String) New Value
// 	 * Return:      (Boolean) True - Successfully Updated | False - Error
// 	 ************************************/
//	function update($primaryKeyName, $primaryKeyValue, $columnNameToUpdate, $columnValue){ 
//
//		//Custom SQL Injection Escaping HERE
//
//		$statement = "UPDATE players SET $columnNameToUpdate = '$columnValue' WHERE $primaryKeyName = '$primaryKeyValue'";
//		$results   = $this->db->query($statement);
//		if($results){
//			return true;
//		}else{
//			return false;
//		}
//
//	}//End update()
//

    function inc_goals($id){
    	$statement = "UPDATE players SET goals = goals+1 WHERE id=$id";
		$results   = $this->db->query($statement);
		if($results){
			return true;
		}else{
			return false;
		}
    }

	/***********************************
 	 * GetAll:       Returns all the records in the database.
 	 * Parameters:   NA
 	 * Return:      (MultiDimensional-Array)String
 	 ************************************/
	function getAll(){ 

		//Custom SQL Injection Escaping HERE

		$statement = "SELECT CONCAT_WS(' ',name, possition), cc FROM players";
		$results   = $this->db->getAll($statement);

		return $results;

	}//End getAll()
	
	function getAllClean(){
		$statement = "SELECT CONCAT_WS(' ',name, possition), c.county, goals, p.id FROM players p INNER JOIN countries c ON p.cc = c.id";
		$results   = $this->db->getAll($statement);
		return $results;
	}
	
	function getTopGoalscorers(){ 

		//Custom SQL Injection Escaping HERE

		$statement = "SELECT CONCAT_WS(' ',name, possition), c.county, goals FROM players p INNER JOIN countries c ON p.cc = c.id WHERE goals > 0 ORDER BY goals DESC LIMIT 10";
		$results   = $this->db->getAll($statement);

		return $results;

	}


//	/***********************************
// 	 * GetObject:   Returns a specific record form the batabase.
// 	 * Parameters:  (Int) Primary Key Value
// 	 * Return:      (Array)String
// 	 ************************************/
//	function getObject($primaryKeyName, $primaryKeyValue){ 
//
//		//Custom SQL Injection Escaping HERE
//
//		$statement = "SELECT id, possition, name, cc FROM players WHERE ".$primaryKeyName." = '".$primaryKeyValue."'";
//		$results   = $this->db->getAll($statement);
//
//		return $results;
//
//	}//End getObject()


}//End Class Players
?>